package com.example.studyktdemo.adapter;

import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.studyktdemo.bean.HomeBean;
import com.youth.banner.adapter.BannerAdapter;

import org.jetbrains.annotations.NotNull;

import java.util.List;
import java.util.Objects;

public class HomeBannerAdapter extends BannerAdapter<HomeBean.Issue.Item,HomeBannerAdapter.BannerViewHolder> {


    public HomeBannerAdapter(List<HomeBean.Issue.Item> data) {
        super(data);
    }

    @Override
    public HomeBannerAdapter.BannerViewHolder onCreateHolder(ViewGroup viewGroup, int viewType) {
        ImageView imageView = new ImageView(viewGroup.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return new BannerViewHolder(imageView);
    }

    @Override
    public void onBindView(HomeBannerAdapter.BannerViewHolder bannerViewHolder, HomeBean.Issue.Item data, int position, int i1) {

        if(data.getType().equals("video")){
            Glide.with(bannerViewHolder.itemView.getContext()).
                    load(Objects.requireNonNull(data.getData()).getCover()
                    .getFeed()).into(bannerViewHolder.imageView);
            Log.d("banner",data.getData().getTitle());
        }

    }

    public static class BannerViewHolder extends RecyclerView.ViewHolder {
        ImageView imageView;
        public BannerViewHolder(@NonNull @NotNull ImageView itemView) {
            super(itemView);
            imageView = itemView;
        }
    }
}
